package model;

//import java.sql.Connection;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import oracle.jdbc.OracleDriver;
import oracle.jdbc.pool.OracleDataSource;

//import java.sql.DriverManager;
//import java.sql.ResultSet;
//import java.sql.SQLException;
//import java.sql.Statement;
//import java.util.logging.Level;
//import java.util.logging.Logger;
//import oracle.jdbc.OracleDriver;
//import oracle.jdbc.pool.OracleDataSource;

public class DataBaseConnection {
//private String jdbcURL = "jdbc:mysql://localhost:3306/rplo";
//    private String user = "root";
//    private String password = "";
    private Connection conn = null;

    private String jdbcURL = "jdbc:Oracle:thin:@172.23.9.185:1521:orcl";
    private String user = "MHS105314003";
    private String password = "MHS105314003";

    public DataBaseConnection() {
         
        try {
            DriverManager.registerDriver(new OracleDriver());
            conn = DriverManager.getConnection(jdbcURL, user, password);
            System.out.println("koneksi berhasil");
        } catch (Exception ex) {
            System.out.println("message: " + ex.getMessage());
        }
    }

    

    public boolean isConnected() {
        if (conn != null) {
            return true;
        } else {
            return false;
        }
    }

    public boolean getClosed() {
        if (isConnected()) {
            try {
                conn.close();
                conn = null;
            } catch (SQLException ex) {
                ex.printStackTrace();
            }
            return true;
        } else {
            return false;
        }
    }

    public String getJdbcURL() {
        return jdbcURL;
    }

    public void setJdbcURL(String jdbcURL) {
        this.jdbcURL = jdbcURL;
    }

    public String getUser() {
        return user;
    }

    public void setUser(String user) {
        this.user = user;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Connection getConnection() {
        return conn;
    }

    public void setConn(Connection connection) {
        this.conn = connection;
    }

    public static void main(String[] args) {

        DataBaseConnection conn = new DataBaseConnection();
        try {
            String query = "select * from daftar";
            Statement statement = conn.getConnection().createStatement();
            ResultSet result = statement.executeQuery(query);

            while (result.next()) {
                System.out.println("Nama : " + result.getString("namalengkap"));
                System.out.println("Alamat : " + result.getString("alamat"));
                
                
            }
            statement.close();
        } catch (Exception ex) {
            System.out.println("message: " + ex.getMessage());
        }

    }
}
